
<template>
  <div>
    <!-- <div style="text-align:right">
      <el-button type="success" icon="el-icon-plus" size="small" @click="onClickCreate">新增</el-button>
    </div> -->

    <el-table :data="tableData" row-key="id" style="width: 100%">
      <el-table-column type="index" label="#" />
      <el-table-column prop="leadLimit" label="上限" sortable />
      <el-table-column prop="leadRatio" label="比例" sortable />
      <!-- <el-table-column prop="state" label="操作" min-width="25%">
        <template slot-scope="scope">
          <el-button type="text" @click="onClickEdit(scope.row)">编辑</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <!-- 暂时无需新增编辑 -->
    <!-- <el-dialog :visible.sync="dialogFormVisible" :destroy-on-close="true" width="50%" :title="form.isEdit ? '编辑' : '新增'">
      <el-form ref="form" :rules="rules" :model="form">
        <el-form-item required label="金额" label-width="80px">
          <el-input-number v-model="form.leadLimit" :min="0" prop='leadLimit' placeholder="请输入金额" clearable />
        </el-form-item>
        <el-form-item required label="比列" label-width="80px">
          <el-input-number v-model="form.leadRatio" :precision="2" :step="0.01" :min="0.01" :max="1" prop='leadRatio' placeholder="请输入比例" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="onClickCancel">取 消</el-button>
        <el-button type="primary" @click="onClickSubmit">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
export default {
  name: '',
  components: {},
  props: {},
  data() {
    return {
      dialogFormVisible: false,
      tableData: [],
      form: {
        leadLimit: null,
        leadRatio: null,
        isEdit: false,
      },
      rules: {
        leadLimit: [{ required: true, message: '请输入金额', trigger: 'blur' }],
        leadRatio: [{ required: true, message: '请输入比例', trigger: 'blur' }],
      },
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  computed: {},
  methods: {
    init() {
      this.getRatioLeadList();
    },

    // 重制表单
    onClickCancel() {
      this.dialogFormVisible = false;
      this.$refs['form'].resetFields();
    },

    // 表单提交
    onClickSubmit() {
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return;

        const { isEdit } = this.form;
        if (!isEdit) {
          delete this.form.id;
        }
        this.setRatioAgent();
      });
    },

    // 新增
    onClickCreate() {
      this.form = { ...this.form, ...{ isEdit: false } };
      this.dialogFormVisible = true;
    },

    // 编辑
    onClickEdit(row) {
      this.form = { ...this.form, ...row, ...{ isEdit: true } };
      this.dialogFormVisible = true;
    },

    async getRatioLeadList() {
      const response = await this.$api.getRatioLeadList();
      const { data } = response;
      this.tableData = [data];
    },

    async setRatioAgent() {
      const params = { ...{}, ...this.form };
      delete params.isEdit;
      const response = await this.$api.setRatioLead(params);
      if (response.success) {
        this.$message.success('编辑成功');
        this.dialogFormVisible = false;
        this.getRatioLeadList();
      }
    },
  },
};
</script>

<style lang='scss' scoped>
</style>
